#ifndef _RUDP_H_
#define _RUDP_H_

//#include <deque>

#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <semaphore.h>
#endif


#ifndef WIN32
#define PACK_NO_PADDING  __attribute__ ((__packed__)) //wrchen 090206
#else
#define PACK_NO_PADDING
#endif

#ifdef __cplusplus
extern "C" {
#endif

#pragma pack( push, 1 )

struct RUDP_Info_Pkt_t
{
	unsigned int		recvCount;								//
	unsigned int        lostCount;
	unsigned int        resendCount1;							// 
	unsigned int		recvResendCount1;
	unsigned int        resendCount2;
	unsigned int        recvResendCount2;
}PACK_NO_PADDING;

struct RUDP_Loss_Pkt_t
{
	unsigned int        lostCount;
	unsigned char       reserved[32];							// 

}PACK_NO_PADDING;

#pragma pack( pop )

#define RUDP_SUCCESS				(0)
#define RUDP_ERROR				(1)

#define RUDP_NORMAL             (0)
#define RUDP_HIGH               (1)

typedef void (* pInfoCallBack)(struct RUDP_Info_Pkt_t *pFrmHdr, unsigned int context);
typedef void (* pLossCallBack)(struct RUDP_Loss_Pkt_t *pFrmHdr, unsigned int context);
typedef void (* pFrameCallBack)(unsigned char *pData, unsigned int len, unsigned int ID, unsigned int context);

typedef void (* pMaxBitCallBack)(unsigned int context);

int RUDP_Init();
int RUDP_CreateSender(int *pHandle);
int RUDP_SetDestAddr(int handle, struct sockaddr_in destaddr);

//int RUDP_SendFrame(int handle, unsigned char *pData, unsigned int len, unsigned int ID);
//int RUDP_SendFrame(int handle, unsigned char *pData, unsigned int len, char * ID);
int RUDP_SendFrame(int handle, unsigned char *pData, unsigned int len, char *ID, unsigned int linkID);

int RUDP_CreateReceiver(int *pHandle, unsigned short port);
int RUDP_RegInfoCallBack(int handle,pInfoCallBack pCBFunc, unsigned int context);
int RUDP_RegLossCallBack(int handle,pLossCallBack pCBFunc, unsigned int context);
int RUDP_RegFrameCallBack(int handle,pFrameCallBack pCBFunc, unsigned int context);

int RUDP_AddID(int handle, unsigned int ID);
int RUDP_DelID(int handle, unsigned int ID);
int RUDP_Sender_OpenSocket(int handle);
int RUDP_Sender_CloseSocket(int handle);

int RUDP_SetSpeedMode(int handle, int mode);
int RUDP_SetBitRates(int handle, int bitRates);

int RUDP_RegMaxBitCallBack(int handle,pMaxBitCallBack pCBFunc, unsigned int context);
int RUDP_getBufUseInfo(int handle);
//int RUDP_getRsndBufUseInfo(int handle);
#ifdef __cplusplus
}
#endif

#endif












